package com.example.demo.controller;

import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/createOrUpdateUser")
    public String createOrUpdateUser(@RequestBody Map<String, String> requestBody) {
        try {
            String openid = requestBody.get("openid");
            if (openid == null) {
                return "Error: openid is missing";
            }
            userService.createOrUpdateUser(openid);
            return "User created or updated successfully.";
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }
}